package test;

import java.awt.Graphics;

public class SimpleShapesDrawing {
    public static void drawShapes(Graphics g) {
        // 绘制倒等腰三角
        drawInvertedIsoscelesTriangle(g, 200, 100, 150, 150);
        // 绘制空心直角三角形
        drawHollowRightTriangle(g, 300, 200, 200, 100);
        // 绘制菱形
        drawDiamond(g, 400, 300, 100);
    }
    // 绘制倒等腰三角的方法
    public static void drawInvertedIsoscelesTriangle(Graphics g, int x, int y, int baseLength, int height) {
        g.drawLine(x, y, x + baseLength, y);
        g.drawLine(x + baseLength, y, x, y + height);
        g.drawLine(x, y + height, x + baseLength, y + height);
    }
    // 绘制空心直角三角形的方法
    public static void drawHollowRightTriangle(Graphics g, int x, int y, int width, int height) {
        g.drawLine(x, y, x + width, y);
        g.drawLine(x + width, y, x + width, y + height);
        g.drawLine(x + width, y + height, x, y + height);
    }
    // 绘制菱形的方法
    public static void drawDiamond(Graphics g, int x, int y, int sideLength) {
        g.drawLine(x, y, x + sideLength, y);
        g.drawLine(x + sideLength, y, x + sideLength / 2, y + sideLength);
        g.drawLine(x + sideLength / 2, y + sideLength, x, y + sideLength);
        g.drawLine(x, y + sideLength, x + sideLength / 2, y);
    }
}

